package io.zerous.engine.math

/**
 * Created by Zerous on 2018/9/23.
 */

public fun square(value: Float) = value * value

public fun distance2(x: Float, y:Float, x1: Float, y1: Float) = square(x - x1) + square(y - y1)

public fun distance(x: Float, y:Float, x1: Float, y1: Float) = Math.sqrt(distance2(x, y, x1, y1).toDouble()).toFloat()

fun randomVec2(xRange: Float, yRange: Float) : Vector2 {
    val x: Float = (Math.random() * xRange - xRange/2f).toFloat()
    val y: Float = (Math.random() * yRange - yRange/2f).toFloat()
    return Vector2(x, y)
}